package com.dly.blog.utile;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Author: DaiLiYu
 * @Date: 2023/7/19 10:30
 */
public class CollectionUtils {

    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

    public static boolean isNotEmpty(Collection<?> collection) {
        return !isEmpty(collection);
    }

    /**
     * 数组类型判断
     * @param args
     * @return
     */
    public static boolean isEmpty(Object... args) {
        return args == null || args.length == 0;
    }


    /**
     * 将两个集合比较 并得到差集
     * @param olds 需要删除的
     * @param news 需要添加的
     * @param <T>
     */
    public static <T> void  getDifferenceResult(List<T> olds, List<T> news){
        List<T> retains = new ArrayList<>(olds);
        retains.retainAll(news);
        if (!olds.isEmpty()) olds.removeAll(retains);
        if (!news.isEmpty()) news.removeAll(retains);
    }
}
